from django.shortcuts import render
from datetime import datetime


# Create your views here.
class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def eat(self):
        print(f"{self.name} is eating.")
        self.name = "John"


def home(request):
    return render(request, 'index.html')


def try_page(request, num):
    return render(request, 'try.html')


def info_page(request):
    username = "admin"
    book = {"name": "Python", "author": "Guido"}
    books = [
        {"name": "Python", "author": "Guido"},
        {"name": "Java", "author": "James Gosling"},
    ]

    context = {
        "username": username,
        "book": book,
        "books": books,
        "person": Person(name="Guido", age=20)
    }
    return render(request, 'info.html', context=context)


def biaoqian(request):
    age = 11
    context = {
        "age": age,
        "person": Person(name="Guido", age=20),
        "books": [
            {"name": "张三", "age": 18},
            {"name": "李四", "age": 22},
            {"name": "as,dnar  klaf", "age": 12.12345}
        ],
        "html_content": "<h1>Hello World</h1>",
        "datetime_now": datetime.now(),
        "text": False,
        "text1": None,
    }
    return render(request, 'biaoqian.html', context=context)


def base(request):
    age = 18
    context = {
        "age": age,
        "person": Person(name="Guido", age=20),
        "books": [
            {"name": "张三", "age": 18},
            {"name": "李四", "age": 22},
            {"name": "as,dnar  klaf", "age": 12.12345}
        ],
        "html_content": "<h1>Hello World</h1>",
        "datetime_now": datetime.now(),
        "text": False,
        "text1": None,
        "list": [1, 2, 3, 4, 5],
    }
    return render(request, 'base.html', context=context)
